package controllers

import (
	"cms/enums"
	"cms/models"
	"cms/utils"
	"github.com/astaxie/beego/orm"
)

type BackendUserController struct {
	BaseController
}

func (c *BackendUserController) Edit() {
	if c.Ctx.Request.Method == "POST" {
		c.Save()
	}
}

func (c *BackendUserController) Save() {
	m := models.BackendUser{}
	o := orm.NewOrm()
	var err error
	if err = c.ParseForm(&m); err != nil {
		c.jsonResult(enums.JRCodeFailed, "获取数据失败", m.Id)
	}
	//删除已关联的历史数据???

	if m.Id == 0 {
		m.UserPwd = utils.String2md5(m.UserPwd)
		if _, err := o.Insert(&m); err != nil {
			c.jsonResult(enums.JRCodeFailed, "添加失败", m.Id)
		}
	} else {

	}
}
